import 'package:flutter/material.dart';
import 'package:myapp/ui/discovery_page.dart';
import 'package:myapp/ui/home_page.dart';
import 'package:myapp/ui/navi_page.dart';
import 'package:myapp/ui/person_page.dart';
import 'package:myapp/ui/system_page.dart';
//stful stless
class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

List<Widget> _pages = [
  HomePage(),
  SystemPage(),
  DiscoveryPage(),
  NaviPage(),
  PersonPage(),
];

class _MainPageState extends State<MainPage> with TickerProviderStateMixin {
  PageController _pageController = PageController();
  int _page = 0;

  @override
  void initState() {
    super.initState();
    print("initState");
  }

  @override
  void deactivate() {
    super.deactivate();
    print("deactivate");
  }

  @override
  void dispose() {
    print("dispose");
    super.dispose();
    _pageController?.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(

      body: PageView(
        controller: _pageController,
        physics: NeverScrollableScrollPhysics(),
        children: _pages,
        onPageChanged: (index) {
          setState(() {
            _page = index;
          });
        },
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _page,
        onTap: (index) => _pageController.jumpToPage(index),
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
          BottomNavigationBarItem(icon: Icon(Icons.list), label: "体系"),
          BottomNavigationBarItem(icon: Icon(Icons.category), label: "发现"),
          BottomNavigationBarItem(icon: Icon(Icons.paste), label: "项目"),
          BottomNavigationBarItem(icon: Icon(Icons.person), label: "我的"),
        ],
      ),
    );
  }
}
